/*
    Copyright 2011 Peter Pratscher
 
    This file is part of Surveillance.NET.

    Surveillance.NET is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    Surveillance.NET is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Surveillance.NET. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Net.Mail;
using System.Runtime.Serialization;
using ActiveUp.Net.Mail;

namespace SurveillanceDotNet.Model
{
    public delegate void NewMailEventHandler(object sender, NewMailEventArgs e);

    public class NewMailEventArgs : EventArgs
    {
        public Message Message { get; set; }

        public NewMailEventArgs() : base() { }
    }

    [Serializable]
    public abstract class MailAccount : ISerializable
    {
        public MailAddress FromAddress { get; set; }
        public string Password { get; set; }

        public abstract void SendMail(MailAddress toAddress, string subject, string body, List<System.Net.Mail.Attachment> attachments);

        public abstract override string ToString();

        public event NewMailEventHandler NewMail;

        protected virtual void OnNewMail(NewMailEventArgs e)
        {
            if (NewMail != null)
            {
                NewMail(this, e);
            }
        }

        public MailAccount() { }

        public abstract void CheckNewMail();

        #region ISerializable Implementation
        protected MailAccount(SerializationInfo info, StreamingContext context)
        {
            FromAddress = new MailAddress(info.GetString("ToAddressAdress"), info.GetString("ToAddressDisplayName"));
            Password = info.GetString("Password");
        }
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("ToAddressAdress", FromAddress.Address);
            info.AddValue("ToAddressDisplayName", FromAddress.DisplayName);
            info.AddValue("Password", Password);
        }
        #endregion
    }
}
